package com.he.projects.custom.service;

import cn.hutool.core.util.IdUtil;
import com.he.projects.custom.bean.ResultT;
import com.he.projects.custom.dao.MenuDao;
import com.he.projects.custom.entity.Menu;
import com.he.projects.custom.enums.StateEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author heyanjing
 * date:2020-07-13 2020/7/13:22:29
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 500, rollbackFor = {Exception.class, RuntimeException.class})
public class MenuService {

    @Autowired
    private MenuDao menuDao;

    public ResultT insert(Menu menu) {
        menu.setMenuId(IdUtil.simpleUUID());
        menu.setCreateDate(new Date());
        menu.setStatus(StateEnum.VALID.getCode());
        this.menuDao.insert(menu);
        return ResultT.success();
    }

    public ResultT treeList() {
        List<Menu> menuList = this.menuDao.findEnable();
        return ResultT.successWithData(menuList);
    }
    public ResultT<List<Menu>> find() {
        List<Menu> menuList = this.menuDao.findBystatus();
        return ResultT.successWithData(menuList);
    }


}
